package cn.tedu.medicalmanagementsystem.manager.controller;


import cn.tedu.medicalmanagementsystem.base.response.JsonResult;
import cn.tedu.medicalmanagementsystem.manager.pojo.dto.*;
import cn.tedu.medicalmanagementsystem.manager.pojo.vo.EscortVO;
import cn.tedu.medicalmanagementsystem.manager.pojo.vo.UserVO;
import cn.tedu.medicalmanagementsystem.manager.service.ManagerEscortService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "陪诊员管理模块")
@RequestMapping("/v1/managerEscort")
public class ManagerEscortController {

    @Autowired
    ManagerEscortService managerEscortService;

    //添加陪诊员
    @PostMapping("/add")
    @ApiOperation("添加陪诊员")
    public JsonResult add(@RequestBody EscortAddParam escortAddParam) {
        log.debug("开始处理添加陪诊员请求：{}", escortAddParam);
        EscortVO escortVO = managerEscortService.add(escortAddParam);
        return JsonResult.ok(escortVO);
    }

    //  修改陪诊员信息
    @PostMapping("/update")
    @ApiOperation("修改陪诊员信息")
    public JsonResult update(@RequestBody EscortUpdateParam escortUpdateParam) {
        log.debug("开始处理修改陪诊员请求：{}", escortUpdateParam);
        EscortVO escortVO = managerEscortService.update(escortUpdateParam);
        return JsonResult.ok(escortVO);
    }

    //根据ID删除陪诊员
    @PostMapping("/delete/{id}")
    @ApiOperation("删除陪诊员")
    public JsonResult delete(EscortDelParam escortDelParam) {
        log.debug("开始处理删除陪诊员请求：{}", escortDelParam);
        //判断陪诊员是否存在
        managerEscortService.deleteById(escortDelParam.getId());
        return JsonResult.ok();
    }
    //查询所有陪诊员列表
    @GetMapping("/escorts")
    @ApiOperation("查询陪诊员列表")
    public JsonResult list() {
        log.debug("开始处理查询陪诊员列表请求");
        List<EscortVO> list = managerEscortService.allEscorts();
        return JsonResult.ok(list);
    }


    @GetMapping("/{id}")
    @ApiOperation("根据ID查询陪诊员详情")
    public JsonResult getById(@PathVariable Long id) {
        log.debug("开始处理查询陪诊员详情请求：{}", id);
        EscortVO escortVO = managerEscortService.getById(id);
        return JsonResult.ok(escortVO);
    }

    @PostMapping("/name")
    @ApiOperation("根据真实姓名查询陪诊员")
    public JsonResult getByUsername(@RequestBody EscortVO escortVO) {
        log.debug("开始处理查询陪诊员请求：{}", escortVO);
        EscortVO escortVO1 = managerEscortService.getByUsername(escortVO);
        return JsonResult.ok(escortVO1);
    }

    @GetMapping("select")
    public JsonResult selectEscort(EscortListQuery escortListQuery) {
        log.debug("开始处理查询陪诊员请求：{}", escortListQuery);
        List<EscortVO> list = managerEscortService.selectEscort(escortListQuery);
        return JsonResult.ok(list);
    }

}
